package com.neusoft.controller;

import com.neusoft.model.ActivitySearch;
import com.neusoft.po.Sale;
import com.neusoft.service.SaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 打折活动请求控制器
 *
 * @author Lucifer
 * @since 2021/5/17 12:06
 */
@RestController
@RequestMapping("/sale")
@Api(tags = "打折活动接口")
public class SaleController {

    @Resource
    private SaleService saleService;

    @PostMapping("/page")
    @ApiOperation("打折活动集合")
    public Object page(@RequestBody ActivitySearch pageSearch) {
        return saleService.page(pageSearch);
    }

    @PostMapping("/list")
    @ApiOperation("打折活动集合")
    public List<Sale> list() {
        return saleService.listAll();
    }

    @GetMapping
    @ApiOperation("查询打折信息")
    @ApiImplicitParam(value = "打折ID", name = "id", required = true)
    public Sale get(Integer id) {
        return saleService.getById(id);
    }

    @PostMapping
    @ApiOperation("打折活动保存")
    public Integer save(@RequestBody Sale sale) {
        saleService.save(sale);
        return sale.getId();
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("批量打折活动删除")
    public Integer delete(@PathVariable("ids") Integer[] ids) {
        return saleService.delete(ids);
    }
}
